home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#21 (Jun 87)
/
format source
/
BuffStuff.a
next >
Wrap
Text File
|
1987-05-07
|
3KB
|
104 lines
;********************** File:BuffStuff.a ************************
;****************************************************************
;
; This file contains a couple of subroutines that are used for
; manipulating the buffers.
BLANKS ON
IMPORT (BadB_List,BadB_Num,BadB_Out):DATA
INCLUDE 'FormatEqu.a'
; PROC ClearBuff
;
; This subroutine is used to clear a buffer. It gets the address
; in A0 and the length in bytes in D0 (long word value).
ClearBuff PROC EXPORT ;subroutine for export to other
;moduals at link time.
movem.l D0/A0,-(SP) ;save registers
subq #1,D0 ;D0=count-1; branch after clr.b
blt.s exit ;exit if passed buffer length =0
buf_loop
clr.b (A0,D0.L) ;clear the byte
dbra D0,buf_loop ;branch when D0>0
exit
movem.l (SP)+,D0/A0 ;restore the registers
rts
ENDPROC
; PROC OutBuff
;
; OutBuff takes our list of bad blocks and reformats so it can be
; used as the defect data block that gets transfered after the
; format command. First we place the size of the defect data
; block minus the 4 byte header in byte 3. Then we start loading
; in the bad block records. They must have aready been sorted
; in order of increasing cylinder number. The fields in each
; record are of the form: 3 bytes for the cylinder, one byte for
; the head number and a long word for the bytes from index value.
;
; Registers:
; A0 Points to curent position in BadB_List
; (our sorted list of bad blocks used for input)
; A1 Points to current position in BadB_Out
; (our output buffer used in formatting)
; D1 Scratch
; D0 Loop index
OutBuff PROC EXPORT
; Equates for offset at beginning of bad block output buffer:
ByteCount EQU 3
movem.l D0-D1/A0-A1,-(A7) ;save registers on stack
; Clear the output buffer before we start transfering records.
lea BadB_Out(A5),A0
move.l #MaxBBOutLen,D0
jsr ClearBuff
move.l BadB_Num(A5),D0 ;get the number of defects
beq exit ;exit if it's zero
subq.l #1,D0 ;adjust D0 (dbra after transfer)
lea BadB_List(A5),A0 ;initialize A0
lea BadB_Out(A5),A1 ;initialize A1
clr.l D1 ;clear scratch
move.l BadB_Num(A5),D1
lsl.l #3,D1 ;multipy count by 8 bytes
move.b D1,ByteCount(A1) ;place LSB of count in header
adda.l #4,A1 ;incr output pointer to 1st rec.
loop
move.l CylBBuff(A0),D1 ;load cylinder# into scratch area
move.b D1,CylOut_LB(A1) ;move low byte into record
lsr.l #8,D1
move.b D1,CylOut_MB(A1) ;move middle byte into record
lsr.l #8,D1
move.b D1,CylOut_HB(A1) ;move high byte into record
move.b 3+HeadBBuff(A0),HeadOut(A1)
;move head number into record,
;moving byte value of long
move.l BFIBBuff(A0),BFIOut(A1)
;transfer Byte_From_Index value
adda.l #16,A0 ;A0 points to next input record
adda.l #8,A1 ;A1 points to next output record
dbra D0,Loop ;decrement loop counter & repeat
exit
movem.l (A7)+,D0-D1/A0-A1 ;restore registers
rts
ENDPROC
END